﻿using System;

namespace Theoreme.Teaching.AOP.Sample01
{
    public abstract class Entity : ISecurable
    {
        protected Entity()
        {
            this.Id = Guid.NewGuid();
            this.UserRoles = new UserRoleList();
        }

        public Guid Id { get; private set; }

        public Entity Parent { get; protected set; }

        public UserRoleList UserRoles { get; private set; }

        public bool IsInRole( User user, string role )
        {
            if ( this.UserRoles.ContainsUserRole( user, role ) )
                return true;

            if ( this.Parent != null )
                return this.Parent.IsInRole( user, role );

            return false;
        }
    }
}